"""
@File    : get_local_data.py
@Author  : qve-wzy
@Time    : 2020/9/2 0002 15:41
"""
from util.read_ini import ReadIni

class GetByLocal:
    '''
    读取ini 获得对应的位置
    '''
    def __init__(self,driver):
        self.driver = driver

    def get_element(self,key):
        read_ini = ReadIni()
        local = read_ini.get_value(key)
        if local != None:
            by = local.split('>')[0]
            local_by = local.split('>')[1]
            try:
                if by == 'id':
                    print("开始获取id元素--->",local_by)
                    id = self.driver.find_element_by_id(local_by)
                    return id

                elif by == 'className':
                    print("开始获取class元素--->",local_by)
                    return self.driver.find_element_by_class_name(local_by)

                else:
                    print("开始获取其他元素--->",local_by)
                    return self.driver.find_element_by_xpath(local_by)

            except:
                self.driver.save_screenshot("../jpg/test02.png")
                return None
        else:
            return None
